import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input,Select,Button, InputNumber, Radio, Modal, Cascader  } from 'antd'
// import style from './detail/index.less'

const FormItem = Form.Item
const Option = Select.Option
const formItemLayout = {
  labelCol: {
    span: 6,
  },
  wrapperCol: {
    span: 14,
  },
}

const modal = ({
  item = {},
  executePlan,
  form: {
    getFieldDecorator,
    validateFields,
    getFieldsValue,
  },
  ...modalProps
}) => {
  const {testHostList}=modalProps
  const {sutList}=modalProps
  const {releaseList}=modalProps
  const handleOk = () => {
    validateFields((errors) => {
      if (errors) {
        return
      }
      let currentPlan=JSON.parse(sessionStorage.getItem('currentPlan'))
      const data = {
        ...getFieldsValue(),
        // plan_name_id:currentPlan.pk,
        plan_name:currentPlan.name,
        product_name_id:currentPlan.productId,
        suite_names:currentPlan.suiteName

      }
      executePlan(data)

      // goto(data)
    })
  }
  const osType=(val)=>{
    if(val=='0'){
      return 'Linux'
    }else if(val=='1'){
      return 'Windows'
    }else if(val=='2'){
      return 'Docker'
    }
  }
  const children = [];
  children.push(<Option key='0'>AUTO</Option>)
  for (let i = 0; i < testHostList.length; i++) {
    children.push(<Option key={testHostList[i].pk}>{testHostList[i].fields.ip}-{osType(testHostList[i].fields.os_type)}</Option>);
  }

  const sutchildren = [];
  for (let i = 0; i < sutList.length; i++) {
    sutchildren.push(<Option key={sutList[i].pk}>{sutList[i].fields.ip}</Option>);
  }
  const releasechildren=[];
  for (let i = 0; i < releaseList.length; i++) {
    releasechildren.push(<Option key={releaseList[i].pk}>{releaseList[i].fields.name}</Option>);
  }


  return (
  <Form layout="horizontal">

    <FormItem label="测试机IP" hasFeedback {...formItemLayout}>
      {getFieldDecorator('testhost_ip_id', {
        initialValue: '0',
        rules: [
          {
            required: true,
          },
        ],
      })(<Select>
        {children}
      </Select>)}
    </FormItem>
    <FormItem label="服务机IP" hasFeedback {...formItemLayout}>
      {getFieldDecorator('sut_ip_id', {
        initialValue: '',
        rules: [
          {
            required: true,
          },
        ],
      })(
        <Select>
        {sutchildren}
      </Select>)}
    </FormItem>
    <FormItem label="产品版本" hasFeedback {...formItemLayout}>
      {getFieldDecorator('release', {
        initialValue: '',
        rules: [
          {
            required: true,
          },
        ],
      })(<Select>
        {releasechildren}
      </Select>)}
    </FormItem>
    <FormItem label="浏览器" hasFeedback {...formItemLayout}>
      {getFieldDecorator('browser', {
        initialValue: '1',
        rules: [
          {
            required: true,
          },
        ],
      })(
        <Select >
          <Option value="1">Chrome</Option>
          <Option value="2">Firefox</Option>
          <Option value="0">IE</Option>
        </Select>)}
    </FormItem>
    <FormItem label="系统" hasFeedback {...formItemLayout}>
      {getFieldDecorator('os_type', {
        initialValue: '0',
        rules: [
          {
            required: true,
          },
        ],
      })(
        <Select>
          <Option value="0">Linux</Option>
          <Option value="1">Windows</Option>
          <Option value="2">Docker</Option>
        </Select>)}
    </FormItem>
    <FormItem wrapperCol={{ span: 16, offset: 6 }} style={{ marginTop: 24 }}>
      <Button type="primary" htmlType="submit" onClick={handleOk}>提交</Button>
    </FormItem>

  </Form>

  )
}

modal.propTypes = {
  form: PropTypes.object.isRequired,
  type: PropTypes.string,
  item: PropTypes.object,
  // onOk: PropTypes.func,
}

export default Form.create()(modal)
